/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package flightlifter;

import GUI.Button;
import GUI.GUILayout;
import GUI.GUIListener;
import GUI.VerticalLayout;
import java.util.Vector;
import org.lwjgl.opengl.GL11;

/**
 *
 * @author Matt
 */
public class Avionics extends Node implements SensorSource{

    OrthoNormalBasis ONB;

    float [] data = new float[5];
    String [] titles = new String[5];

    public Avionics(OrthoNormalBasis ONB, GUILayout probeMenu, GUIListener listener) {
        this.ONB = ONB;
        red = 0;
        green = .0f;
        blue = .25f;
        titles[0] = "Airspeed";
        titles[1] = "Roll Rate";
        titles[2] = "Pitch Rate";
        titles[3] = "Yaw Rate";
        titles[4] = "Altitude";


        for (int i =0; i < titles.length; i++){
            probeMenu.add(new Button(titles[i],listener, this, i));
        }

    }

    @Override
    public void physics() {

        PVector temp;

        temp = PVector.sub(ONB.middle.pos, ONB.middle.lastPos);
        data[0] = temp.mag() * FlightLifter.FRAMERATE;
        
        data[4] = ONB.middle.pos.y;
    }

    @Override
    public void render(int mode) {
        GL11.glLineWidth(4.f);
        if (selected == 1) {
            GL11.glColor3f(1.0f, 1.0f, 0.0f);
        } else {
            GL11.glColor3f(red, green, blue);
        }
        GL11.glBegin(GL11.GL_TRIANGLES);    // Drawing Using Triangles
        GL11.glVertex3f(ONB.front.pos.x, ONB.front.pos.y, ONB.front.pos.z);
        GL11.glVertex3f(ONB.middle.pos.x, ONB.middle.pos.y, ONB.middle.pos.z);
        GL11.glVertex3f(ONB.up.pos.x, ONB.up.pos.y, ONB.up.pos.z);
        GL11.glEnd();
    }

    public Avionics(String [] line, Vector <Node> nodes, VerticalLayout probeMenu, GUIListener listener){
        this(new OrthoNormalBasis((Point)nodes.elementAt(Integer.parseInt(line[1])),
             (Point)nodes.elementAt(Integer.parseInt(line[2])),
             (Point)nodes.elementAt(Integer.parseInt(line[3]))),
             probeMenu,listener);
    }

    public String pickle(Vector<Node> nodes) {
        return "A,"
                + ONB.pickle(nodes);
    }

    @Override
    public PVector getCentroid() {
        return ONB.middle.pos.get();
    }

    @Override
    public PVector getScreenSpaceCentroid() {
        float[] ret = GLProject.project(ONB.middle.pos.x,
                ONB.middle.pos.y,
                ONB.middle.pos.z);

        return new PVector(ret[0], ret[1], 0);
    }

        public boolean dependsOn(Point p) {

            return false;

    }

    public float[] getDataArray() {
        return data;
    }

    public String[] getTitleArray() {
        return titles;
    }


}
